/**
 *  This file is part of AugeasWH.
 *
 *  AugeasWH. is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  AugeasWH. is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with AugeasWH.  If not, see <http://www.gnu.org/licenses/>.
 */

package cz.fit.vutbr.pis2012.augeaswh.persistence;

import java.io.Serializable;

import javax.persistence.*;

import java.sql.Timestamp;
import java.util.List;
import static javax.persistence.CascadeType.ALL;


/**
 * The persistent class for the orders database table.
 * 
 */
@Entity
@Table(name="orders")
public class Order implements Serializable, AugeasWHEntity {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;

	@Column(name="income_date")
	private Timestamp incomeDate;

	private String name;

	@Column(name="process_date")
	private Timestamp processDate;

	//bi-directional many-to-one association to Subject

    @ManyToOne
	@JoinColumn(name = "subject_id", referencedColumnName = "id")
	private Subscriber subscriber;

	//bi-directional many-to-one association to OrdersStockType
	@OneToMany(mappedBy="order", cascade = ALL)
	private List<OrdersStockType> ordersStockTypes;

    public Order() {
    }

	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Timestamp getIncomeDate() {
		return this.incomeDate;
	}

	public void setIncomeDate(Timestamp incomeDate) {
		this.incomeDate = incomeDate;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Timestamp getProcessDate() {
		return this.processDate;
	}

	public void setProcessDate(Timestamp processDate) {
		this.processDate = processDate;
	}

	public Subscriber getSubscriber() {
		return this.subscriber;
	}

	public void setSubscriber(Subscriber subsriber) {
		this.subscriber = subsriber;
	}
	
	public List<OrdersStockType> getOrdersStockTypes() {
		return this.ordersStockTypes;
	}

	public void setOrdersStockTypes(List<OrdersStockType> ordersStockTypes) {
		this.ordersStockTypes = ordersStockTypes;
	}
	
	public int getOrderedStockItemsCount() {
		return this.ordersStockTypes.size();
	}	
}